package com.wanli.agent.homepage;

import android.app.Dialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.CustomListener;
import com.bigkoo.pickerview.listener.OnTimeSelectChangeListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.contrarywind.view.WheelView;
import com.ethanhua.skeleton.SkeletonScreen;
import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.wanli.agent.R;
import com.wanli.agent.base.BaseActivity;
import com.wanli.agent.base.DataCallBack;
import com.wanli.agent.bean.BusinessDataOverviewBean;
import com.wanli.agent.bean.BusinessDataTodayBean;
import com.wanli.agent.bean.BusinessMerchantInfoBean;
import com.wanli.agent.bean.BusinessProviderInfoBean;
import com.wanli.agent.bean.UserInfoBean;
import com.wanli.agent.homepage.adapter.MerchantDataListAdapter;
import com.wanli.agent.homepage.adapter.ProviderDataListAdapter;
import com.wanli.agent.homepage.model.HomePageModelImpl;
import com.wanli.agent.homepage.model.IHomePageModel;
import com.wanli.agent.utils.DateTimeUtil;
import com.wanli.agent.utils.LogUtils;
import com.wanli.agent.utils.SPManager;
import com.wanli.agent.utils.ToastUtil;
import com.wanli.agent.widget.AppTitleBar;
import com.wanli.agent.widget.ViewLoading;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 经营数据详情
 * 待完善：
 */
public class BusinessDataActivity extends BaseActivity implements OnRefreshLoadMoreListener {

    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tvDealAmountToday)
    TextView tvDealAmountToday;
    @BindView(R.id.tvDealCountToday)
    TextView tvDealCountToday;
    @BindView(R.id.tvAvgPriceToday)
    TextView tvAvgPriceToday;
    @BindView(R.id.tvIncomeAmountToday)
    TextView tvIncomeAmountToday;
    @BindView(R.id.tvAddProviderToday)
    TextView tvAddProviderToday;
    @BindView(R.id.tvAddMerchantToday)
    TextView tvAddMerchantToday;
    @BindView(R.id.tvYestoday)
    TextView tvYestoday;
    @BindView(R.id.tvTimePeriod)
    TextView tvTimePeriod;
    @BindView(R.id.tvDealAmountTotal)
    TextView tvDealAmountTotal;
    @BindView(R.id.tvIncomeAmountTotal)
    TextView tvIncomeAmountTotal;
    @BindView(R.id.tvAddProviderTotal)
    TextView tvAddProviderTotal;
    @BindView(R.id.tv_yesterday_money)
    TextView tvYesterdayMoney;
    @BindView(R.id.tvAddMerchantTotal)
    TextView tvAddMerchantTotal;
    @BindView(R.id.tvProductVersion)
    TextView tvProductVersion;
    @BindView(R.id.rl_zsffs)
    RelativeLayout rlZsffs;
    @BindView(R.id.rl_zssh)
    RelativeLayout rlZssh;
    @BindView(R.id.etSearch)
    EditText etSearch;
    @BindView(R.id.view_cancel)
    View viewCancel;
    @BindView(R.id.ll_search)
    LinearLayout llSearch;
    @BindView(R.id.tvSearch)
    TextView tvSearch;
    @BindView(R.id.tvYestoday2)
    TextView tvYestoday2;
    @BindView(R.id.tvTimePeriod2)
    TextView tvTimePeriod2;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvDealAmount)
    TextView tvDealAmount;
    @BindView(R.id.tvDealCount)
    TextView tvDealCount;
    @BindView(R.id.tv_line1)
    TextView tvLine1;
    @BindView(R.id.tv_line2)
    TextView tvLine2;
    @BindView(R.id.tv_zsffs)
    TextView tvZsffs;
    @BindView(R.id.tv_zssh)
    TextView tvZssh;
    @BindView(R.id.rvProvider)
    RecyclerView rvProvider;
    @BindView(R.id.rvMerchant)
    RecyclerView rvMerchant;
    @BindView(R.id.tvBranchName)
    TextView tvBranchName;
    @BindView(R.id.srlProvider)
    SmartRefreshLayout srlProvider;
    @BindView(R.id.srlMerchant)
    SmartRefreshLayout srlMerchant;
    @BindView(R.id.ll_no_data1)
    LinearLayout llNoData1;
    @BindView(R.id.ll_no_data2)
    LinearLayout llNoData2;
    @BindView(R.id.nsv)
    NestedScrollView nsv;

    private SkeletonScreen skeletonScreen;
    private IHomePageModel homePageModel;
    private UserInfoBean userInfoBean;
    private List<BusinessProviderInfoBean.DataBean> providerList = new ArrayList<>();
    private List<BusinessMerchantInfoBean.DataBean> merchantList = new ArrayList<>();
    private ProviderDataListAdapter providerAdapter;
    private MerchantDataListAdapter merchantAdapter;
    private String productVersion = "0";
    private int productClickTimes = 0;// 产品版本按钮点击次数统计
    private int pageSize = 20;
    private int providerPage = 1;
    private int merchantPage = 1;
    private String providerKeyword = "";
    private String merchantKeyword = "";

    private String startTimeProvider = "";
    private String endTimeProvider = "";
    private String monthProvider = "";
    private String yesterdayProvider = getYesterday();

    private String startTimeMerchant = "";
    private String endTimeMerchant = "";
    private String monthMerchant = "";
    private String yesterdayMerchant = getYesterday();

    private String startTimeOverview = "";
    private String endTimeOverview = "";
    private String monthOverview = "";
    private String yesterdayOverview = getYesterday();

    private String providerSeq1 = "desc";
    private String providerSeq2 = "";
    private String merchantSeq1 = "desc";
    private String merchantSeq2 = "";
    private int roleFlag = 0;// 0-直属服务商，1-直属商户
    private int dateFlag = -1;// -1-昨天，0-按日查询，1-按月查询，2-自定义区间起始日期，3-自定义区间结束日期

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_data);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        homePageModel = new HomePageModelImpl();
        userInfoBean = new Gson().fromJson(SPManager.getInstance().getUserInfoJson(), UserInfoBean.class);
        LogUtils.e("经营数据", "userInfoBean：" + SPManager.getInstance().getUserInfoJson());
        tvBranchName.setText(userInfoBean.getData().getName());
        if (userInfoBean == null || userInfoBean.getData() == null) {
            ToastUtil.showShort("获取用户信息失败，请稍后再试！");
            finish();
        }
        if (userInfoBean.getData().getId() == 1) {
            tvProductVersion.setVisibility(View.VISIBLE);
            productVersion = "0";
            tvProductVersion.setText("产品版本(全部)");
            tvProductVersion.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_switch), null);
        } else if (userInfoBean.getData().getId() == 2) {
            tvProductVersion.setVisibility(View.GONE);
            productVersion = "1";
            tvProductVersion.setText("标准版");
            tvProductVersion.setCompoundDrawables(null, null, null, null);
        } else if (userInfoBean.getData().getId() == 3) {
            tvProductVersion.setVisibility(View.GONE);
            productVersion = "2";
            tvProductVersion.setText("智能版");
            tvProductVersion.setCompoundDrawables(null, null, null, null);
        }

        etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    if (roleFlag == 0) {
                        if (!TextUtils.isEmpty(providerKeyword)) {
                            refreshData(roleFlag);
                        }
                    } else {
                        if (!TextUtils.isEmpty(merchantKeyword)) {
                            refreshData(roleFlag);
                        }
                    }
                    return true;
                }
                return false;
            }
        });
        etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (roleFlag == 0) {
                    providerKeyword = etSearch.getText().toString().trim();

                    if (!TextUtils.isEmpty(providerKeyword)) {
                        viewCancel.setVisibility(View.VISIBLE);
                    } else {
                        viewCancel.setVisibility(View.GONE);
                    }
                } else {
                    merchantKeyword = etSearch.getText().toString().trim();

                    if (!TextUtils.isEmpty(merchantKeyword)) {
                        viewCancel.setVisibility(View.VISIBLE);
                    } else {
                        viewCancel.setVisibility(View.GONE);
                    }
                }

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        srlProvider.setRefreshHeader(new ClassicsHeader(mActivity));//设置Header
        srlProvider.setRefreshFooter(new ClassicsFooter(mActivity));//设置Footer
        srlProvider.setOnRefreshLoadMoreListener(this);

        srlMerchant.setRefreshHeader(new ClassicsHeader(mActivity));//设置Header
        srlMerchant.setRefreshFooter(new ClassicsFooter(mActivity));//设置Footer
        srlMerchant.setOnRefreshLoadMoreListener(this);

        providerAdapter = new ProviderDataListAdapter(providerList);
        providerAdapter.setData(yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, roleFlag);
        rvProvider.setLayoutManager(new LinearLayoutManager(mActivity));
        rvProvider.setAdapter(providerAdapter);

        merchantAdapter = new MerchantDataListAdapter(merchantList);
        merchantAdapter.setData(yesterdayMerchant, monthMerchant, startTimeMerchant, endTimeMerchant, roleFlag);
        rvMerchant.setLayoutManager(new LinearLayoutManager(mActivity));
        rvMerchant.setAdapter(merchantAdapter);

        rvProvider.setNestedScrollingEnabled(false);
        rvMerchant.setNestedScrollingEnabled(false);

//        skeletonScreen = Skeleton.bind(rvProvider)
//                .adapter(providerAdapter)
//                .color(R.color.shimmer_color_1)
//                .shimmer(true)
//                .angle(20)
//                .frozen(false)
//                .duration(1000)
//                .count(20)
//                .load(R.layout.item_skeleton_agent_list)
//                .show();
//
//        skeletonScreen = Skeleton.bind(recyclerView)
//                .adapter(listAdapter)
//                .color(R.color.shimmer_color_1)
//                .shimmer(true)
//                .angle(20)
//                .frozen(false)
//                .duration(1000)
//                .count(20)
//                .load(R.layout.item_skeleton_agent_list)
//                .show();

        nsv.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                //判断是否滑到的底部
                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    //调用刷新控件对应的加载更多方法
                    if (roleFlag == 0) {
                        providerPage++;
                        ViewLoading.showProgress(mActivity, "加载中...");
                        getProviderInfo();
                        srlProvider.finishLoadMore(30000);
                    } else {
                        merchantPage++;
                        ViewLoading.showProgress(mActivity, "加载中...");
                        getMerchantInfo();
                        srlMerchant.finishLoadMore(30000);
                    }
                }
            }
        });

        getBusinessDataToday();
        getDataOverview();
        getProviderInfo();
        getMerchantInfo();
    }

    public void refreshData(int flag) {
        if (flag == 0) {
            providerPage = 1;
            providerList.clear();
            providerAdapter.notifyDataSetChanged();
            getProviderInfo();
            srlProvider.finishRefresh(30000);
        } else {
            merchantPage = 1;
            merchantList.clear();
            merchantAdapter.notifyDataSetChanged();
            getMerchantInfo();
            srlMerchant.finishRefresh(30000);
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        if (roleFlag == 0) {
            providerPage++;
            getProviderInfo();
            srlProvider.finishLoadMore(30000);
        } else {
            merchantPage++;
            getMerchantInfo();
            srlMerchant.finishLoadMore(30000);
        }
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        refreshData(roleFlag);
    }

    private Button btnCancel;
    private Button btnSubmit;
    private TextView tvTitle;
    private TextView tvYesterday;
    private TextView tvDay;
    private TextView tvMonth;
    private TextView tvPeriod;
    private TextView tvDayOrMonth;
    private TextView tvStartTime;
    private TextView tvEndTime;
    private LinearLayout llPeriod;
    private LinearLayout timepicker;
    private TimePickerView pvTime;
    private WheelView day;

    private void showCustomTimePicker(final int taskFlag) {//时间选择器初始化，自定义布局
        /**
         * @description
         *
         * 注意事项：
         * 自定义布局中，id为 optionspicker 或者 timepicker 的布局以及其子控件必须要有，否则会报空指针。
         * 具体可参考demo 里面的两个自定义layout布局。
         */
        pvTime = new TimePickerBuilder(mActivity, (date, v) -> {
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setLayoutRes(R.layout.dialog_date_select, new CustomListener() {
                    @Override
                    public void customLayout(View sheetView) {
                        btnCancel = (Button) sheetView.findViewById(R.id.btnCancel);
                        btnSubmit = (Button) sheetView.findViewById(R.id.btnSubmit);
                        tvTitle = (TextView) sheetView.findViewById(R.id.tvTitle);
                        tvYesterday = (TextView) sheetView.findViewById(R.id.tvYesterday);
                        tvDay = (TextView) sheetView.findViewById(R.id.tvDay);
                        tvMonth = (TextView) sheetView.findViewById(R.id.tvMonth);
                        tvPeriod = (TextView) sheetView.findViewById(R.id.tvPeriod);
                        tvDayOrMonth = (TextView) sheetView.findViewById(R.id.tvDayOrMonth);
                        tvStartTime = (TextView) sheetView.findViewById(R.id.tvStartTime);
                        tvEndTime = (TextView) sheetView.findViewById(R.id.tvEndTime);
                        llPeriod = (LinearLayout) sheetView.findViewById(R.id.llPeriod);
                        timepicker = (LinearLayout) sheetView.findViewById(R.id.timepicker);
                        day = (WheelView) sheetView.findViewById(R.id.day);

                        tvDayOrMonth.setText(getYesterday());
                        tvDayOrMonth.setVisibility(View.VISIBLE);
                        llPeriod.setVisibility(View.GONE);
                        timepicker.setVisibility(View.INVISIBLE);

                        if (taskFlag == 0) {
                            if (!TextUtils.isEmpty(startTimeOverview)) {
                                tvStartTime.setText(startTimeOverview);
                            }
                            if (!TextUtils.isEmpty(endTimeOverview)) {
                                tvEndTime.setText(endTimeOverview);
                            }
                        } else if (taskFlag == 1) {
                            if (roleFlag == 0) {
                                if (!TextUtils.isEmpty(startTimeProvider)) {
                                    tvStartTime.setText(startTimeProvider);
                                }
                            } else if (roleFlag == 1) {
                                if (!TextUtils.isEmpty(startTimeMerchant)) {
                                    tvStartTime.setText(startTimeMerchant);
                                }
                            }
                            if (roleFlag == 0) {
                                if (!TextUtils.isEmpty(endTimeProvider)) {
                                    tvEndTime.setText(endTimeProvider);
                                }
                            } else if (roleFlag == 1) {
                                if (!TextUtils.isEmpty(endTimeMerchant)) {
                                    tvEndTime.setText(endTimeMerchant);
                                }
                            }
                        }
                        btnSubmit.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                if (taskFlag == 0) {
                                    startTimeOverview = "";
                                    endTimeOverview = "";
                                    monthOverview = "";
                                    yesterdayOverview = "";
                                    if (dateFlag == -1) {
                                        yesterdayOverview = getYesterday();
//                                        tvTimePeriod.setText(yesterdayOverview);
                                        tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                        tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                    } else if (dateFlag == 0) {
                                        //TODO 判断日期合法性
                                        if (TextUtils.isEmpty(tvDayOrMonth.getText().toString())) {
                                            yesterdayOverview = DateTimeUtil.format(new Date());
                                        } else {
                                            yesterdayOverview = tvDayOrMonth.getText().toString();
                                        }
                                        tvTimePeriod.setText(yesterdayOverview);
                                    } else if (dateFlag == 1) {
                                        //TODO 判断日期合法性
                                        if (TextUtils.isEmpty(tvDayOrMonth.getText().toString())) {
                                            monthOverview = DateTimeUtil.formatMonth(new Date());
                                        } else {
                                            monthOverview = tvDayOrMonth.getText().toString();
                                        }
                                        tvTimePeriod.setText(monthOverview);
                                    } else if (dateFlag == 2 || dateFlag == 3) {
                                        //TODO 判断日期合法性
                                        startTimeOverview = tvStartTime.getText().toString();
                                        endTimeOverview = tvEndTime.getText().toString();
                                        if (TextUtils.isEmpty(startTimeOverview) || TextUtils.isEmpty(endTimeOverview)) {
                                            ToastUtil.showShort("开始日期或结束日期不能为空！");
                                            startTimeOverview = "";
                                            endTimeOverview = "";
                                            return;
                                        }
                                        tvTimePeriod.setText(startTimeOverview + "至" + endTimeOverview);
                                    }
                                    getDataOverview();
                                } else if (taskFlag == 1) {
                                    if (roleFlag == 0) {
                                        startTimeProvider = "";
                                        endTimeProvider = "";
                                        monthProvider = "";
                                        yesterdayProvider = "";
                                    } else if (roleFlag == 1) {
                                        startTimeMerchant = "";
                                        endTimeMerchant = "";
                                        monthMerchant = "";
                                        yesterdayMerchant = "";
                                    }
                                    if (dateFlag == -1) {
                                        if (roleFlag == 0) {
                                            yesterdayProvider = getYesterday();
                                            tvTimePeriod2.setText("");
                                        } else if (roleFlag == 1) {
                                            yesterdayMerchant = getYesterday();
                                            tvTimePeriod2.setText("");
                                        }
                                        tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                        tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                    } else if (dateFlag == 0) {
                                        //TODO 判断日期合法性
                                        if (TextUtils.isEmpty(tvDayOrMonth.getText().toString())) {
                                            if (roleFlag == 0) {
                                                yesterdayProvider = DateTimeUtil.format(new Date());
                                                tvTimePeriod2.setText(yesterdayProvider);
                                            } else if (roleFlag == 1) {
                                                yesterdayMerchant = DateTimeUtil.format(new Date());
                                                tvTimePeriod2.setText(yesterdayMerchant);
                                            }
                                        } else {
                                            if (roleFlag == 0) {
                                                yesterdayProvider = tvDayOrMonth.getText().toString();
                                                if (yesterdayProvider.equals(getYesterday())) {
                                                    tvTimePeriod2.setText("");
                                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                                } else {
                                                    tvTimePeriod2.setText(yesterdayProvider);
                                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                                }
                                            } else if (roleFlag == 1) {
                                                yesterdayMerchant = tvDayOrMonth.getText().toString();
                                                if (yesterdayMerchant.equals(getYesterday())) {
                                                    tvTimePeriod2.setText("");
                                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                                } else {
                                                    tvTimePeriod2.setText(yesterdayMerchant);
                                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                                }
                                            }
                                        }
                                    } else if (dateFlag == 1) {
                                        //TODO 判断日期合法性
                                        if (TextUtils.isEmpty(tvDayOrMonth.getText().toString())) {
                                            if (roleFlag == 0) {
                                                monthProvider = DateTimeUtil.formatMonth(new Date());
                                                tvTimePeriod2.setText(monthProvider);
                                            } else if (roleFlag == 1) {
                                                monthMerchant = DateTimeUtil.formatMonth(new Date());
                                                tvTimePeriod2.setText(monthMerchant);
                                            }
                                        } else {
                                            if (roleFlag == 0) {
                                                monthProvider = tvDayOrMonth.getText().toString();
                                                tvTimePeriod2.setText(monthProvider);
                                            } else if (roleFlag == 1) {
                                                monthMerchant = tvDayOrMonth.getText().toString();
                                                tvTimePeriod2.setText(monthMerchant);
                                            }
                                        }
                                    } else if (dateFlag == 2 || dateFlag == 3) {
                                        //TODO 判断日期合法性
                                        if (roleFlag == 0) {
                                            startTimeProvider = tvStartTime.getText().toString();
                                            endTimeProvider = tvEndTime.getText().toString();
                                            if (TextUtils.isEmpty(startTimeProvider) || TextUtils.isEmpty(endTimeProvider)) {
                                                ToastUtil.showShort("开始日期或结束日期不能为空！");
                                                startTimeProvider = "";
                                                endTimeProvider = "";
                                                return;
                                            }
                                            tvTimePeriod2.setText(startTimeProvider + "至" + endTimeProvider);
                                        } else if (roleFlag == 1) {
                                            startTimeMerchant = tvStartTime.getText().toString();
                                            endTimeMerchant = tvEndTime.getText().toString();
                                            if (TextUtils.isEmpty(startTimeMerchant) || TextUtils.isEmpty(endTimeMerchant)) {
                                                ToastUtil.showShort("开始日期或结束日期不能为空！");
                                                startTimeMerchant = "";
                                                endTimeMerchant = "";
                                                return;
                                            }
                                            tvTimePeriod2.setText(startTimeMerchant + "至" + endTimeMerchant);
                                        }
                                    }
                                    refreshData(roleFlag);
                                }
                                pvTime.dismiss();
                            }
                        });
                        btnCancel.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                pvTime.dismiss();
                            }
                        });

                        tvYesterday.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = -1;
                                tvDayOrMonth.setText(getYesterday());
                                tvDayOrMonth.setVisibility(View.VISIBLE);
                                llPeriod.setVisibility(View.GONE);
                                timepicker.setVisibility(View.INVISIBLE);
                                setDlgBtnStyle(0);
                                if (taskFlag == 0) {
                                    tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                    tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                } else {
                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                                }
                            }
                        });
                        tvDay.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = 0;
                                tvDayOrMonth.setText(DateTimeUtil.format(new Date()));
                                tvDayOrMonth.setVisibility(View.VISIBLE);
                                llPeriod.setVisibility(View.GONE);
                                timepicker.setVisibility(View.VISIBLE);
                                day.setVisibility(View.VISIBLE);
                                setDlgBtnStyle(1);
                                if (taskFlag == 0) {
                                    tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                } else {
                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                }
                            }
                        });
                        tvMonth.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = 1;
                                tvDayOrMonth.setText(DateTimeUtil.formatMonth(new Date()));
                                tvDayOrMonth.setVisibility(View.VISIBLE);
                                llPeriod.setVisibility(View.GONE);
                                timepicker.setVisibility(View.VISIBLE);
                                day.setVisibility(View.GONE);
                                setDlgBtnStyle(2);
                                if (taskFlag == 0) {
                                    tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                } else {
                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                }
                            }
                        });
                        tvPeriod.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = 2;
                                tvDayOrMonth.setVisibility(View.GONE);
                                llPeriod.setVisibility(View.VISIBLE);
                                timepicker.setVisibility(View.VISIBLE);
                                day.setVisibility(View.VISIBLE);
                                setDlgBtnStyle(3);
                                if (taskFlag == 0) {
                                    tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                } else {
                                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                                }
                            }
                        });

                        tvDayOrMonth.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        });
                        tvStartTime.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = 2;
                                tvStartTime.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_line_blue));
                                tvEndTime.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_commercial_3));
                            }
                        });
                        tvEndTime.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dateFlag = 3;
                                tvStartTime.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_commercial_3));
                                tvEndTime.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_line_blue));
                            }
                        });

                    }
                })
                .setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
                    @Override
                    public void onTimeSelectChanged(Date date) {
                        if (dateFlag == 0) {
                            tvDayOrMonth.setText(DateTimeUtil.format(date));
                        } else if (dateFlag == 1) {
                            tvDayOrMonth.setText(DateTimeUtil.formatMonth(date));
                        } else if (dateFlag == 2) {
                            tvStartTime.setText(DateTimeUtil.format(date));
                        } else if (dateFlag == 3) {
                            tvEndTime.setText(DateTimeUtil.format(date));
                        }
                        LogUtils.e("经营数据", "日期选择器：" + DateTimeUtil.format(date));
                    }
                })
                .setSubmitColor(getResources().getColor(R.color.text_color_2))//确定按钮文字颜色
                .setSubCalSize(14)
                .setCancelColor(getResources().getColor(R.color.text_color_2))//取消按钮文字颜色
                .setTitleBgColor(getResources().getColor(R.color.white))
                .setDividerColor(getResources().getColor(R.color.line_color_gray))
                .setTextColorCenter(getResources().getColor(R.color.text_color_2))
                .setContentTextSize(15)
                .setLineSpacingMultiplier(2)
//                .setDate(selectedDate)// 如果不设置的话，默认是系统时间*/
//                .setRangDate(startDate, endDate)//起始终止年月日设定
                .isDialog(true) //默认设置false ，内部实现将DecorView 作为它的父控件。
                .setOutSideCancelable(false)
                .build();

        Dialog mDialog = pvTime.getDialog();
        if (mDialog != null) {
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.BOTTOM);

            params.leftMargin = 0;
            params.rightMargin = 0;
            pvTime.getDialogContainerLayout().setLayoutParams(params);

            Window window = mDialog.getWindow();
            if (window != null) {
                window.setWindowAnimations(R.style.picker_view_slide_anim);//修改动画样式
                window.getDecorView().setPadding(0, 0, 0, 0);
                WindowManager.LayoutParams lp = window.getAttributes();
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
                lp.gravity = Gravity.BOTTOM;
            }
        }
//        pvTime.setDate(Calendar.getInstance());//注：根据需求来决定是否使用该方法（一般是精确到秒的情况），此项可以在弹出选择器的时候重新设置当前时间，避免在初始化之后由于时间已经设定，导致选中时间与当前时间不匹配的问题。
        pvTime.show();

    }

    public void getBusinessDataToday() {
        homePageModel.getBusinessDataToday(productVersion, new DataCallBack<BusinessDataTodayBean>() {
            @Override
            public void onSuccessful(BusinessDataTodayBean bean) {
                LogUtils.e("经营数据resp", "BusinessDataTodayBean：" + new Gson().toJson(bean));
                tvDealAmountToday.setText(bean.getData().getTrade_money());
                tvDealCountToday.setText(bean.getData().getTotal_number());
                tvAvgPriceToday.setText(bean.getData().getUnit_price());
                tvIncomeAmountToday.setText(bean.getData().getIncome_amount());
                tvAddProviderToday.setText(bean.getData().getAdd_channel());
                tvAddMerchantToday.setText(bean.getData().getAdd_merchant());
            }

            @Override
            public void onFailed(String msg, String code) {
                LogUtils.e("经营数据resp", "BusinessDataTodayBean：" + code + "-" + msg);
            }
        });
    }

    public void getDataOverview() {
        homePageModel.getDataOverview(productVersion, yesterdayOverview, monthOverview, startTimeOverview, endTimeOverview, new DataCallBack<BusinessDataOverviewBean>() {
            @Override
            public void onSuccessful(BusinessDataOverviewBean bean) {
                LogUtils.e("经营数据resp", "BusinessDataOverviewBean：" + new Gson().toJson(bean));
                tvDealAmountTotal.setText(bean.getData().getTrade_money());
                tvIncomeAmountTotal.setText(bean.getData().getIncome_amount());
                tvAddProviderTotal.setText(bean.getData().getAdd_channel());
                tvAddMerchantTotal.setText(bean.getData().getAdd_merchant());
            }

            @Override
            public void onFailed(String msg, String code) {
                LogUtils.e("经营数据resp", "BusinessDataOverviewBean：" + code + "-" + msg);
            }
        });
    }

    public void getProviderInfo() {
        homePageModel.getProviderInfo(productVersion, "", pageSize, providerPage, providerKeyword, yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, providerSeq1, providerSeq2, new DataCallBack<BusinessProviderInfoBean>() {
            @Override
            public void onSuccessful(BusinessProviderInfoBean bean) {
                ViewLoading.dismissProgress();
                LogUtils.e("经营数据resp", "BusinessProviderInfoBean：" + new Gson().toJson(bean));
                if (bean.getData() != null && bean.getData().size() > 0) {
                    providerList.addAll(bean.getData());
                    if (providerPage == 1) {
                        srlProvider.finishRefresh();
                    } else {
                        srlProvider.finishLoadMore();
                    }
                } else {
                    if (providerPage != 1) {
                        srlProvider.finishLoadMoreWithNoMoreData();
                    } else {
                        srlProvider.finishRefresh();
                    }
                }
                if (providerList.size() > 0) {
                    llNoData1.setVisibility(View.GONE);
                } else {
                    llNoData1.setVisibility(View.VISIBLE);
                }
                providerAdapter.setData(yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, roleFlag);
                providerAdapter.notifyDataSetChanged();
                if (providerPage == 1) {
//                    skeletonScreen.hide();
                }
            }

            @Override
            public void onFailed(String msg, String code) {
                ViewLoading.dismissProgress();
                LogUtils.e("经营数据resp", "BusinessProviderInfoBean：" + code + "-" + msg);
            }
        });
    }

    public void getMerchantInfo() {
        homePageModel.getMerchantInfo(productVersion, "", pageSize, merchantPage, merchantKeyword, yesterdayMerchant, monthMerchant, startTimeMerchant, endTimeMerchant, merchantSeq1, merchantSeq2, new DataCallBack<BusinessMerchantInfoBean>() {
            @Override
            public void onSuccessful(BusinessMerchantInfoBean bean) {
                ViewLoading.dismissProgress();
                LogUtils.e("经营数据", "getMerchantInfo：" + new Gson().toJson(bean));
                if (bean.getData() != null && bean.getData().size() > 0) {
                    merchantList.addAll(bean.getData());
                    if (merchantPage == 1) {
                        srlMerchant.finishRefresh();
                    } else {
                        srlMerchant.finishLoadMore();
                    }
                } else {
                    if (providerPage != 1) {
                        srlMerchant.finishLoadMoreWithNoMoreData();
                    } else {
                        srlMerchant.finishRefresh();
                    }
                }
                if (merchantList.size() > 0) {
                    llNoData2.setVisibility(View.GONE);
                } else {
                    llNoData2.setVisibility(View.VISIBLE);
                }
                merchantAdapter.notifyDataSetChanged();
                if (merchantPage == 1) {
//                    skeletonScreen.hide();
                }
            }

            @Override
            public void onFailed(String msg, String code) {
                ViewLoading.dismissProgress();
                LogUtils.e("经营数据", "getMerchantInfo：" + code + "-" + msg);
            }
        });
    }

    @OnClick({R.id.tvProductVersion, R.id.rl_zsffs, R.id.rl_zssh, R.id.tvTimePeriod, R.id.tvTimePeriod2, R.id.tvYestoday, R.id.tvYestoday2, R.id.tvSearch, R.id.view_cancel, R.id.tvDealAmount, R.id.tvDealCount})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvProductVersion:
                if (userInfoBean.getData().getId() == 1) {
                    productClickTimes = productClickTimes + 1;
                    LogUtils.e("经营数据", "productClickTimes：" + productClickTimes);
                    if (productClickTimes % 3 == 0) {
                        productVersion = "0";
                        tvProductVersion.setText("产品版本(全部)");
                        tvProductVersion.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_switch), null);
                    } else if (productClickTimes % 3 == 1) {
                        productVersion = "1";
                        tvProductVersion.setText("标准版");
                        tvProductVersion.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                    } else if (productClickTimes % 3 == 2) {
                        productVersion = "2";
                        tvProductVersion.setText("智能版");
                        tvProductVersion.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
                    }
                }

                resetParams();
                getBusinessDataToday();
                getDataOverview();
                getProviderInfo();
                getMerchantInfo();
                break;
            case R.id.rl_zsffs:
                roleFlag = 0;
                etSearch.setHint("服务商名称");
                tvDealCount.setText("新增商户");
                tvZsffs.setTextColor(ContextCompat.getColor(this, R.color.theme_color));
                tvZssh.setTextColor(ContextCompat.getColor(this, R.color.black));
                tvLine1.setVisibility(View.VISIBLE);
                tvLine2.setVisibility(View.INVISIBLE);
                srlProvider.setVisibility(View.VISIBLE);
                srlMerchant.setVisibility(View.GONE);
                providerAdapter.setData(yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, roleFlag);
                merchantAdapter.setData(yesterdayMerchant, monthMerchant, startTimeMerchant, endTimeMerchant, roleFlag);

                if (providerSeq1.equals("asc")) {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                } else if (providerSeq1.equals("desc")) {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                } else {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                if (providerSeq2.equals("asc")) {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                } else if (providerSeq2.equals("desc")) {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                } else {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                if (!TextUtils.isEmpty(yesterdayProvider)) {
                    if (yesterdayProvider.equals(getYesterday())) {
                        tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                        tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                        tvTimePeriod2.setText("");
                    } else {
                        tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                        tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                        tvTimePeriod2.setText(yesterdayProvider);
                    }
                } else if (!TextUtils.isEmpty(monthProvider)) {
                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                    tvTimePeriod2.setText(monthProvider);
                } else if (!TextUtils.isEmpty(startTimeProvider) && TextUtils.isEmpty(endTimeProvider)) {
                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                    tvTimePeriod2.setText(startTimeProvider + "至" + endTimeProvider);
                }
                break;
            case R.id.rl_zssh:
                roleFlag = 1;
                etSearch.setHint("商户名称");
                tvDealCount.setText("交易笔数");
                tvZsffs.setTextColor(ContextCompat.getColor(this, R.color.black));
                tvZssh.setTextColor(ContextCompat.getColor(this, R.color.theme_color));
                tvLine1.setVisibility(View.INVISIBLE);
                tvLine2.setVisibility(View.VISIBLE);
                srlProvider.setVisibility(View.GONE);
                srlMerchant.setVisibility(View.VISIBLE);
                providerAdapter.setData(yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, roleFlag);
                merchantAdapter.setData(yesterdayMerchant, monthMerchant, startTimeMerchant, endTimeMerchant, roleFlag);

                if (merchantSeq1.equals("asc")) {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                } else if (merchantSeq1.equals("desc")) {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                } else {
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                if (merchantSeq2.equals("asc")) {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                } else if (merchantSeq2.equals("desc")) {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                } else {
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                if (!TextUtils.isEmpty(yesterdayMerchant)) {
                    if (yesterdayMerchant.equals(getYesterday())) {
                        tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                        tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                        tvTimePeriod2.setText("");
                    } else {
                        tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                        tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                        tvTimePeriod2.setText(yesterdayMerchant);
                    }
                } else if (!TextUtils.isEmpty(monthMerchant)) {
                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                    tvTimePeriod2.setText(monthMerchant);
                } else if (!TextUtils.isEmpty(startTimeMerchant) && TextUtils.isEmpty(endTimeMerchant)) {
                    tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.text_color_3));
                    tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_white_25));
                    tvTimePeriod2.setText(startTimeMerchant + "至" + endTimeMerchant);
                }
                break;
            case R.id.tvTimePeriod:
                showCustomTimePicker(0);// 数据总览接口
                break;
            case R.id.tvTimePeriod2:
                showCustomTimePicker(1);// 直属服务商/直属商户接口
                providerAdapter.setData(yesterdayProvider, monthProvider, startTimeProvider, endTimeProvider, roleFlag);
                merchantAdapter.setData(yesterdayMerchant, monthMerchant, startTimeMerchant, endTimeMerchant, roleFlag);
                break;
            case R.id.tvYestoday:
                yesterdayOverview = getYesterday();
                monthOverview = "";
                startTimeOverview = "";
                endTimeOverview = "";
                tvTimePeriod.setText("");
                tvYestoday.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                tvYestoday.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                getDataOverview();
                break;
            case R.id.tvYestoday2:
                if (roleFlag == 0) {
                    yesterdayProvider = getYesterday();
                    monthProvider = "";
                    startTimeProvider = "";
                    endTimeProvider = "";
                } else if (roleFlag == 1) {
                    yesterdayMerchant = getYesterday();
                    monthMerchant = "";
                    startTimeMerchant = "";
                    endTimeMerchant = "";
                }

                tvTimePeriod2.setText("");
                tvYestoday2.setTextColor(ContextCompat.getColor(BusinessDataActivity.this, R.color.white));
                tvYestoday2.setBackground(ContextCompat.getDrawable(BusinessDataActivity.this, R.drawable.bg_common_tangle_blue_25));
                refreshData(roleFlag);
                break;
            case R.id.tvSearch:
                refreshData(roleFlag);
                break;
            case R.id.view_cancel:
                if (roleFlag == 0) {
                    providerKeyword = "";
                } else {
                    merchantKeyword = "";
                }
                etSearch.setText("");
                refreshData(roleFlag);
                break;
            case R.id.tvDealAmount:
                if (roleFlag == 0) {
                    if (providerSeq1.equals("asc")) {
                        providerSeq1 = "desc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    } else if (providerSeq1.equals("desc")) {
                        providerSeq1 = "asc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                    } else {
                        providerSeq1 = "desc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    }
                    providerSeq2 = "";
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                } else {
                    if (merchantSeq1.equals("asc")) {
                        merchantSeq1 = "desc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    } else if (merchantSeq1.equals("desc")) {
                        merchantSeq1 = "asc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                    } else {
                        merchantSeq1 = "desc";
                        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    }
                    merchantSeq2 = "";
                    tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                LogUtils.e("经营数据", "seq1：" + providerSeq1 + " - " + merchantSeq1);
                refreshData(roleFlag);
                break;
            case R.id.tvDealCount:
                if (roleFlag == 0) {
                    if (providerSeq2.equals("asc")) {
                        providerSeq2 = "desc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    } else if (providerSeq2.equals("desc")) {
                        providerSeq2 = "asc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                    } else {
                        providerSeq2 = "desc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    }
                    providerSeq1 = "";
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                } else {
                    if (merchantSeq2.equals("asc")) {
                        merchantSeq2 = "desc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    } else if (merchantSeq2.equals("desc")) {
                        merchantSeq2 = "asc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_desc), null);
                    } else {
                        merchantSeq2 = "desc";
                        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
                    }
                    merchantSeq1 = "";
                    tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);
                }
                LogUtils.e("经营数据", "seq2：" + providerSeq2 + " - " + merchantSeq2);
                refreshData(roleFlag);
                break;
        }
    }

    private void resetParams() {

//        productVersion = "0";
//        productClickTimes = 0;// 产品版本按钮点击次数统计

        providerPage = 1;
        merchantPage = 1;
        providerKeyword = "";
        merchantKeyword = "";
        startTimeProvider = "";
        endTimeProvider = "";
        monthProvider = "";
        yesterdayProvider = getYesterday();
        startTimeMerchant = "";
        endTimeMerchant = "";
        monthMerchant = "";
        yesterdayMerchant = getYesterday();
        startTimeOverview = "";
        endTimeOverview = "";
        monthOverview = "";
        yesterdayOverview = getYesterday();
        providerSeq1 = "desc";
        providerSeq2 = "";
        merchantSeq1 = "desc";
        merchantSeq2 = "";
        roleFlag = 0;// 0-直属服务商，1-直属商户
        dateFlag = -1;// -1-昨天，0-按日查询，1-按月查询，2-自定义区间起始日期，3-自定义区间结束日期

        tvTimePeriod.setText("按时间查询");
        tvTimePeriod2.setText("按时间查询");

        tvDealAmount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_asc), null);
        tvDealCount.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(this, R.mipmap.ic_seq_default), null);

        providerList.clear();
        merchantList.clear();

    }

    /**
     * 获取昨天的日期
     * @return
     */
    private String getYesterday() {
        Calendar calendar = Calendar.getInstance();
        //昨天
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date date = calendar.getTime();
        String yesterday = DateTimeUtil.format(date);
        return yesterday;
    }

    private void setDlgBtnStyle(int btnIndex) {
        tvYesterday.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_3));
        tvDay.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_3));
        tvMonth.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_3));
        tvPeriod.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_3));
        tvYesterday.setTextColor(ContextCompat.getColor(this, R.color.text_color_5));
        tvDay.setTextColor(ContextCompat.getColor(this, R.color.text_color_5));
        tvMonth.setTextColor(ContextCompat.getColor(this, R.color.text_color_5));
        tvPeriod.setTextColor(ContextCompat.getColor(this, R.color.text_color_5));
        if (btnIndex == 0) {
            tvYesterday.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_1));
            tvYesterday.setTextColor(ContextCompat.getColor(this, R.color.white));
        } else if (btnIndex == 1) {
            tvDay.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_1));
            tvDay.setTextColor(ContextCompat.getColor(this, R.color.white));
        } else if (btnIndex == 2) {
            tvMonth.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_1));
            tvMonth.setTextColor(ContextCompat.getColor(this, R.color.white));
        } else if (btnIndex == 3) {
            tvPeriod.setBackground(ContextCompat.getDrawable(this, R.drawable.bg_commercial_1));
            tvPeriod.setTextColor(ContextCompat.getColor(this, R.color.white));
        }
    }

}
